import { IPSSysBIHierarchy } from './ipssys-bihierarchy';
import { IPSSysBILevel } from './ipssys-bilevel';
import { IPSDEField } from '../dataentity/defield/ipsdefield';
import { PSModelObjectImpl } from '../psmodel-object-impl';

export class PSSysBILevelImpl extends PSModelObjectImpl implements IPSSysBILevel {
  get codeName(): string {
    return this.M.codeName;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get levelTag(): string {
    return this.M.levelTag;
  }

  get levelTag2(): string {
    return this.M.levelTag2;
  }

  get levelType(): 'COMMON' | 'TIME_YEARS' | 'TIME_HALFYEARS' | 'TIME_QUARTERS' | 'TIME_MONTHS' | 'TIME_WEEKS' | 'TIME_DAYS' | 'TIME_HOURS' | 'TIME_MINUTES' {
    return this.M.levelType;
  }

  get memo(): string {
    return this.M.memo;
  }

  get name(): string {
    return this.M.name;
  }

  protected textpsdefield: IPSDEField | null = null;

  getTextPSDEField(): IPSDEField | null {
    if (this.textpsdefield != null) return this.textpsdefield;
    const value = this.M.getTextPSDEField;
    if (value == null) {
      return null;
    }
    const ipssysbihierarchy = this.getParentPSModelObject('bi.IPSSysBIHierarchy') as IPSSysBIHierarchy;
    if (ipssysbihierarchy != null) {
      this.textpsdefield = ipssysbihierarchy.getPSDataEntityMust().findPSDEField(value);
    }
    return this.textpsdefield;
  }

  get textPSDEField(): IPSDEField | null {
    return this.getTextPSDEField();
  }

  getTextPSDEFieldMust(): IPSDEField {
    const value = this.getTextPSDEField();
    if (value == null) {
      throw new Error('未指定显示文本属性');
    }
    return value;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  protected valuepsdefield: IPSDEField | null = null;

  getValuePSDEField(): IPSDEField | null {
    if (this.valuepsdefield != null) return this.valuepsdefield;
    const value = this.M.getValuePSDEField;
    if (value == null) {
      return null;
    }
    const ipssysbihierarchy = this.getParentPSModelObject('bi.IPSSysBIHierarchy') as IPSSysBIHierarchy;
    if (ipssysbihierarchy != null) {
      this.valuepsdefield = ipssysbihierarchy.getPSDataEntityMust().findPSDEField(value);
    }
    return this.valuepsdefield;
  }

  get valuePSDEField(): IPSDEField | null {
    return this.getValuePSDEField();
  }

  getValuePSDEFieldMust(): IPSDEField {
    const value = this.getValuePSDEField();
    if (value == null) {
      throw new Error('未指定值属性');
    }
    return value;
  }

  get cls(): string {
    return 'PSSysBILevelImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'bi.IPSBILevel' || cls == 'bi.IPSSysBILevel') return true;
    return super.instanceof(cls);
  }
}
